/**
 * Copyright 2012 Wangxr, vintage.wang@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "AutoConfig.h"

AutoConfig::AutoConfig()
{
	m_TUXONE_GATE_LISTENER_ADDR = "0.0.0.0:26000";
	m_TUXONE_GATE_OTHER_ADDR = "NONE";
	m_TUXONE_GATE_SYNC_INTERVAL = 12;
	m_TUXONE_GATE_CONCURRENT_MAX = 512;
	m_TUXONE_GATE_CONCURRENT_LOWWATER = 128;
	m_TUXONE_GATE_CONCURRENT_HIGHWATER = 2048;
	m_TUXONE_GATE_HOUSEKEEPING_INTERVAL = 10;
	m_TUXONE_GATE_SOCKET_RWTIMEOUT = 90;
	m_TUXONE_GATE_BBL_BERTHMAX = 128;
	m_TUXONE_GATE_WSH_MIN = 1;
	m_TUXONE_GATE_WSH_MAX = 32;
	m_TUXONE_GATE_WSH_ACCESSMAX = 512;
	m_TUXONE_GATE_WSH_THREADPOOL_THREADMIN = 3;
	m_TUXONE_GATE_WSH_THREADPOOL_THREADMAX = 128;
	m_TUXONE_GATE_WSH_THREADPOOL_THREADMAXIDLE = 10;
	m_TUXONE_GATE_WSH_SERVERVALIDTIME = 30;
	m_TUXONE_GATE_WSH_HOUSEKEEPING_INTERVAL = 10;
	m_TUXONE_GATE_WSH_APP_HEART_INTERVAL = 12;
	m_TUXONE_GATE_LOG_ENABLE = true;
	m_TUXONE_GATE_LOG_LEVEL = 4;
	m_TUXONE_GATE_LOG_PRINTWHERE = false;
	m_TUXONE_GATE_LOG_PRINTFILE = true;
	m_TUXONE_GATE_LOG_PRINTCONSOLE = false;

}

AutoConfig::~AutoConfig()
{
}

AutoConfig* AutoConfig::GetInstance()
{
	static AutoConfig *singleton = new AutoConfig();
	return singleton;
}

void AutoConfig::PrintConfig()
{
	const char* tmp = "";
	tmp = tmp;
	logger->info(LTRACE, "tuxone.gate.listener.addr=%s", m_TUXONE_GATE_LISTENER_ADDR.c_str());

	logger->info(LTRACE, "tuxone.gate.other.addr=%s", m_TUXONE_GATE_OTHER_ADDR.c_str());

	logger->info(LTRACE, "tuxone.gate.sync.interval=%d", m_TUXONE_GATE_SYNC_INTERVAL);

	logger->info(LTRACE, "tuxone.gate.concurrent.max=%d", m_TUXONE_GATE_CONCURRENT_MAX);

	logger->info(LTRACE, "tuxone.gate.concurrent.lowWater=%d", m_TUXONE_GATE_CONCURRENT_LOWWATER);

	logger->info(LTRACE, "tuxone.gate.concurrent.highWater=%d", m_TUXONE_GATE_CONCURRENT_HIGHWATER);

	logger->info(LTRACE, "tuxone.gate.housekeeping.interval=%d", m_TUXONE_GATE_HOUSEKEEPING_INTERVAL);

	logger->info(LTRACE, "tuxone.gate.bbl.berthMax=%d", m_TUXONE_GATE_BBL_BERTHMAX);

	logger->info(LTRACE, "tuxone.gate.wsh.min=%d", m_TUXONE_GATE_WSH_MIN);

	logger->info(LTRACE, "tuxone.gate.wsh.max=%d", m_TUXONE_GATE_WSH_MAX);

	logger->info(LTRACE, "tuxone.gate.wsh.accessMax=%d", m_TUXONE_GATE_WSH_ACCESSMAX);

	logger->info(LTRACE, "tuxone.gate.wsh.threadPool.threadMin=%d", m_TUXONE_GATE_WSH_THREADPOOL_THREADMIN);

	logger->info(LTRACE, "tuxone.gate.wsh.threadPool.threadMax=%d", m_TUXONE_GATE_WSH_THREADPOOL_THREADMAX);

	logger->info(LTRACE, "tuxone.gate.wsh.threadPool.threadMaxIdle=%d", m_TUXONE_GATE_WSH_THREADPOOL_THREADMAXIDLE);

	logger->info(LTRACE, "tuxone.gate.wsh.serverValidTime=%d", m_TUXONE_GATE_WSH_SERVERVALIDTIME);

	logger->info(LTRACE, "tuxone.gate.wsh.housekeeping.interval=%d", m_TUXONE_GATE_WSH_HOUSEKEEPING_INTERVAL);

	logger->info(LTRACE, "tuxone.gate.wsh.app.heart.interval=%d", m_TUXONE_GATE_WSH_APP_HEART_INTERVAL);

	logger->info(LTRACE, "tuxone.gate.log.enable=%s", m_TUXONE_GATE_LOG_ENABLE ? "true" : "false");

	logger->info(LTRACE, "tuxone.gate.log.level=%d", m_TUXONE_GATE_LOG_LEVEL);

	logger->info(LTRACE, "tuxone.gate.log.printFile=%s", m_TUXONE_GATE_LOG_PRINTFILE ? "true" : "false");

	logger->info(LTRACE, "tuxone.gate.log.printConsole=%s", m_TUXONE_GATE_LOG_PRINTCONSOLE ? "true" : "false");


}

void AutoConfig::DoPropConstruct()
{
	std::string tmp;

	m_TUXONE_GATE_LISTENER_ADDR = GetPropertyValue("tuxone.gate.listener.addr", m_TUXONE_GATE_LISTENER_ADDR);
	m_TUXONE_GATE_LISTENER_ADDR = m_TUXONE_GATE_LISTENER_ADDR == "NONE" ? "" : m_TUXONE_GATE_LISTENER_ADDR;

	m_TUXONE_GATE_OTHER_ADDR = GetPropertyValue("tuxone.gate.other.addr", m_TUXONE_GATE_OTHER_ADDR);
	m_TUXONE_GATE_OTHER_ADDR = m_TUXONE_GATE_OTHER_ADDR == "NONE" ? "" : m_TUXONE_GATE_OTHER_ADDR;

	m_TUXONE_GATE_SYNC_INTERVAL = GetPropertyValue("tuxone.gate.sync.interval", m_TUXONE_GATE_SYNC_INTERVAL);

	m_TUXONE_GATE_CONCURRENT_MAX = GetPropertyValue("tuxone.gate.concurrent.max", m_TUXONE_GATE_CONCURRENT_MAX);

	m_TUXONE_GATE_CONCURRENT_LOWWATER = GetPropertyValue("tuxone.gate.concurrent.lowWater", m_TUXONE_GATE_CONCURRENT_LOWWATER);

	m_TUXONE_GATE_CONCURRENT_HIGHWATER = GetPropertyValue("tuxone.gate.concurrent.highWater", m_TUXONE_GATE_CONCURRENT_HIGHWATER);

	m_TUXONE_GATE_HOUSEKEEPING_INTERVAL = GetPropertyValue("tuxone.gate.housekeeping.interval", m_TUXONE_GATE_HOUSEKEEPING_INTERVAL);

	m_TUXONE_GATE_SOCKET_RWTIMEOUT = GetPropertyValue("tuxone.gate.socket.rwtimeout", m_TUXONE_GATE_SOCKET_RWTIMEOUT);

	m_TUXONE_GATE_BBL_BERTHMAX = GetPropertyValue("tuxone.gate.bbl.berthMax", m_TUXONE_GATE_BBL_BERTHMAX);

	m_TUXONE_GATE_WSH_MIN = GetPropertyValue("tuxone.gate.wsh.min", m_TUXONE_GATE_WSH_MIN);

	m_TUXONE_GATE_WSH_MAX = GetPropertyValue("tuxone.gate.wsh.max", m_TUXONE_GATE_WSH_MAX);

	m_TUXONE_GATE_WSH_ACCESSMAX = GetPropertyValue("tuxone.gate.wsh.accessMax", m_TUXONE_GATE_WSH_ACCESSMAX);

	m_TUXONE_GATE_WSH_THREADPOOL_THREADMIN = GetPropertyValue("tuxone.gate.wsh.threadPool.threadMin", m_TUXONE_GATE_WSH_THREADPOOL_THREADMIN);

	m_TUXONE_GATE_WSH_THREADPOOL_THREADMAX = GetPropertyValue("tuxone.gate.wsh.threadPool.threadMax", m_TUXONE_GATE_WSH_THREADPOOL_THREADMAX);

	m_TUXONE_GATE_WSH_THREADPOOL_THREADMAXIDLE = GetPropertyValue("tuxone.gate.wsh.threadPool.threadMaxIdle", m_TUXONE_GATE_WSH_THREADPOOL_THREADMAXIDLE);

	m_TUXONE_GATE_WSH_SERVERVALIDTIME = GetPropertyValue("tuxone.gate.wsh.serverValidTime", m_TUXONE_GATE_WSH_SERVERVALIDTIME);

	m_TUXONE_GATE_WSH_HOUSEKEEPING_INTERVAL = GetPropertyValue("tuxone.gate.wsh.housekeeping.interval", m_TUXONE_GATE_WSH_HOUSEKEEPING_INTERVAL);

	m_TUXONE_GATE_WSH_APP_HEART_INTERVAL = GetPropertyValue("tuxone.gate.wsh.app.heart.interval", m_TUXONE_GATE_WSH_APP_HEART_INTERVAL);

	m_TUXONE_GATE_LOG_ENABLE = GetPropertyValue("tuxone.gate.log.enable", m_TUXONE_GATE_LOG_ENABLE);

	m_TUXONE_GATE_LOG_LEVEL = GetPropertyValue("tuxone.gate.log.level", m_TUXONE_GATE_LOG_LEVEL);

	m_TUXONE_GATE_LOG_PRINTWHERE = GetPropertyValue("tuxone.gate.log.printWhere", m_TUXONE_GATE_LOG_PRINTWHERE);

	m_TUXONE_GATE_LOG_PRINTFILE = GetPropertyValue("tuxone.gate.log.printFile", m_TUXONE_GATE_LOG_PRINTFILE);

	m_TUXONE_GATE_LOG_PRINTCONSOLE = GetPropertyValue("tuxone.gate.log.printConsole", m_TUXONE_GATE_LOG_PRINTCONSOLE);

	m_TUXONE_GATE_SYNC_INTERVAL = m_TUXONE_GATE_SYNC_INTERVAL <= 0 ? 1 : m_TUXONE_GATE_SYNC_INTERVAL;
	m_TUXONE_GATE_SYNC_INTERVAL = m_TUXONE_GATE_SYNC_INTERVAL > 2147483647 ? 2147483647 : m_TUXONE_GATE_SYNC_INTERVAL;

	m_TUXONE_GATE_CONCURRENT_MAX = m_TUXONE_GATE_CONCURRENT_MAX <= 0 ? 1 : m_TUXONE_GATE_CONCURRENT_MAX;
	m_TUXONE_GATE_CONCURRENT_MAX = m_TUXONE_GATE_CONCURRENT_MAX > 2147483647 ? 2147483647 : m_TUXONE_GATE_CONCURRENT_MAX;

	m_TUXONE_GATE_CONCURRENT_LOWWATER = m_TUXONE_GATE_CONCURRENT_LOWWATER <= 0 ? 1 : m_TUXONE_GATE_CONCURRENT_LOWWATER;
	m_TUXONE_GATE_CONCURRENT_LOWWATER = m_TUXONE_GATE_CONCURRENT_LOWWATER > 2147483647 ? 2147483647 : m_TUXONE_GATE_CONCURRENT_LOWWATER;

	m_TUXONE_GATE_CONCURRENT_HIGHWATER = m_TUXONE_GATE_CONCURRENT_HIGHWATER <= 0 ? 1 : m_TUXONE_GATE_CONCURRENT_HIGHWATER;
	m_TUXONE_GATE_CONCURRENT_HIGHWATER = m_TUXONE_GATE_CONCURRENT_HIGHWATER > 2147483647 ? 2147483647 : m_TUXONE_GATE_CONCURRENT_HIGHWATER;

	m_TUXONE_GATE_HOUSEKEEPING_INTERVAL = m_TUXONE_GATE_HOUSEKEEPING_INTERVAL <= 0 ? 1 : m_TUXONE_GATE_HOUSEKEEPING_INTERVAL;
	m_TUXONE_GATE_HOUSEKEEPING_INTERVAL = m_TUXONE_GATE_HOUSEKEEPING_INTERVAL > 2147483647 ? 2147483647 : m_TUXONE_GATE_HOUSEKEEPING_INTERVAL;

	m_TUXONE_GATE_SOCKET_RWTIMEOUT = m_TUXONE_GATE_SOCKET_RWTIMEOUT <= 0 ? 1 : m_TUXONE_GATE_SOCKET_RWTIMEOUT;
	m_TUXONE_GATE_SOCKET_RWTIMEOUT = m_TUXONE_GATE_SOCKET_RWTIMEOUT > 2147483647 ? 2147483647 : m_TUXONE_GATE_SOCKET_RWTIMEOUT;

	m_TUXONE_GATE_BBL_BERTHMAX = m_TUXONE_GATE_BBL_BERTHMAX <= 0 ? 1 : m_TUXONE_GATE_BBL_BERTHMAX;
	m_TUXONE_GATE_BBL_BERTHMAX = m_TUXONE_GATE_BBL_BERTHMAX > 2147483647 ? 2147483647 : m_TUXONE_GATE_BBL_BERTHMAX;

	m_TUXONE_GATE_WSH_MIN = m_TUXONE_GATE_WSH_MIN <= 0 ? 1 : m_TUXONE_GATE_WSH_MIN;
	m_TUXONE_GATE_WSH_MIN = m_TUXONE_GATE_WSH_MIN > 2147483647 ? 2147483647 : m_TUXONE_GATE_WSH_MIN;

	m_TUXONE_GATE_WSH_MAX = m_TUXONE_GATE_WSH_MAX <= 0 ? 1 : m_TUXONE_GATE_WSH_MAX;
	m_TUXONE_GATE_WSH_MAX = m_TUXONE_GATE_WSH_MAX > 2147483647 ? 2147483647 : m_TUXONE_GATE_WSH_MAX;

	m_TUXONE_GATE_WSH_ACCESSMAX = m_TUXONE_GATE_WSH_ACCESSMAX <= 0 ? 1 : m_TUXONE_GATE_WSH_ACCESSMAX;
	m_TUXONE_GATE_WSH_ACCESSMAX = m_TUXONE_GATE_WSH_ACCESSMAX > 2147483647 ? 2147483647 : m_TUXONE_GATE_WSH_ACCESSMAX;

	m_TUXONE_GATE_WSH_THREADPOOL_THREADMIN = m_TUXONE_GATE_WSH_THREADPOOL_THREADMIN <= 0 ? 1 : m_TUXONE_GATE_WSH_THREADPOOL_THREADMIN;
	m_TUXONE_GATE_WSH_THREADPOOL_THREADMIN = m_TUXONE_GATE_WSH_THREADPOOL_THREADMIN > 2147483647 ? 2147483647 : m_TUXONE_GATE_WSH_THREADPOOL_THREADMIN;

	m_TUXONE_GATE_WSH_THREADPOOL_THREADMAX = m_TUXONE_GATE_WSH_THREADPOOL_THREADMAX <= 0 ? 1 : m_TUXONE_GATE_WSH_THREADPOOL_THREADMAX;
	m_TUXONE_GATE_WSH_THREADPOOL_THREADMAX = m_TUXONE_GATE_WSH_THREADPOOL_THREADMAX > 2147483647 ? 2147483647 : m_TUXONE_GATE_WSH_THREADPOOL_THREADMAX;

	m_TUXONE_GATE_WSH_THREADPOOL_THREADMAXIDLE = m_TUXONE_GATE_WSH_THREADPOOL_THREADMAXIDLE <= 0 ? 1 : m_TUXONE_GATE_WSH_THREADPOOL_THREADMAXIDLE;
	m_TUXONE_GATE_WSH_THREADPOOL_THREADMAXIDLE = m_TUXONE_GATE_WSH_THREADPOOL_THREADMAXIDLE > 2147483647 ? 2147483647 : m_TUXONE_GATE_WSH_THREADPOOL_THREADMAXIDLE;

	m_TUXONE_GATE_WSH_SERVERVALIDTIME = m_TUXONE_GATE_WSH_SERVERVALIDTIME <= 0 ? 1 : m_TUXONE_GATE_WSH_SERVERVALIDTIME;
	m_TUXONE_GATE_WSH_SERVERVALIDTIME = m_TUXONE_GATE_WSH_SERVERVALIDTIME > 2147483647 ? 2147483647 : m_TUXONE_GATE_WSH_SERVERVALIDTIME;

	m_TUXONE_GATE_WSH_HOUSEKEEPING_INTERVAL = m_TUXONE_GATE_WSH_HOUSEKEEPING_INTERVAL <= 0 ? 1 : m_TUXONE_GATE_WSH_HOUSEKEEPING_INTERVAL;
	m_TUXONE_GATE_WSH_HOUSEKEEPING_INTERVAL = m_TUXONE_GATE_WSH_HOUSEKEEPING_INTERVAL > 2147483647 ? 2147483647 : m_TUXONE_GATE_WSH_HOUSEKEEPING_INTERVAL;

	m_TUXONE_GATE_WSH_APP_HEART_INTERVAL = m_TUXONE_GATE_WSH_APP_HEART_INTERVAL <= 0 ? 1 : m_TUXONE_GATE_WSH_APP_HEART_INTERVAL;
	m_TUXONE_GATE_WSH_APP_HEART_INTERVAL = m_TUXONE_GATE_WSH_APP_HEART_INTERVAL > 2147483647 ? 2147483647 : m_TUXONE_GATE_WSH_APP_HEART_INTERVAL;

	m_TUXONE_GATE_LOG_LEVEL = m_TUXONE_GATE_LOG_LEVEL < 0 ? 0 : m_TUXONE_GATE_LOG_LEVEL;
	m_TUXONE_GATE_LOG_LEVEL = m_TUXONE_GATE_LOG_LEVEL > 7 ? 7 : m_TUXONE_GATE_LOG_LEVEL;


}
